//
//Maquette de test pour les tiles et classe Decor/Niveau
//

//TODO: couche d'abstraction tileset (Theme)
//TODO: mettre la hauteur/largeur tile dans tile, comme dans l'UML
//TODO: traduire en francais

int mapSize = 560;
int tileSize = 20;

Map level1;
Tileset plage;
Tile sable;
Tile eau;

void setup()
{
  size(800,600);
  background(0);
  
  
  sable = new Tile(false, "PlageSable.jpg");
  eau = new Tile(true, "PlageEau.jpg");
  
  
  plage = new Tileset(eau, sable);
  
  level1 = new Map(mapSize/tileSize, plage);
  level1.fill();  
}

void draw()
{
  level1.display();
  plage.display(50,50);
}
  
class Map
{
  int[][] mapArray;
  int mapSize;
  Tileset theme;

  int tileHeight = 20;
  int tileWidth = 40;

  Map(int size, Tileset myTheme)
  {
    mapSize = size;
    mapArray = new int[size][size];
    myTheme = theme;


  }
  
  void fill()
  {
    for(int i=0; i<mapSize; i++)
    {
      for(int j=0; j<mapSize; j++)
      {
        float tileChoice = random(2);
        mapArray[i][j] = int(tileChoice);
      }
    }
  }
  
  void display()
  {
    int xStart;
    for(int i=0; i<mapSize; i++)
    {
      if((i%2 == 0)||(i == 0))
      {
        xStart = 0;
      }
      else
      {
        xStart = 20;
      }
      for(int j=0; j<mapSize; j++)
      {
        
        //theme.collection[mapArray[i][j]].display(tileWidth*j + xStart, (tileHeight/2)*i);
        //theme.collection[1].display(50,50);
        //if(mapArray[i][j]==0)
        //{
        //  sable.display(tileWidth*j + xStart, (tileHeight/2)*i);
        //}
        //if(mapArray[i][j]==1)
        //{
        //  eau.display(tileWidth*j + xStart, (tileHeight/2)*i);
        //}    
      }
    }
  }
}

class Tileset
{
  Tile[] collection;
  
    Tileset(Tile route, Tile mur)
    {
      Tile[] collection0 = new Tile[0];
      Tile[] collection1 = (Tile[]) append(collection0, route);
      Tile[] collection = (Tile[]) append(collection1, mur);
    }
    
    void display(int x, int y)
    {
      collection[0].display(x,y);
      }
}

class Tile
{
  boolean walkable;
  PImage myImage;
  PImage myMask;
  Tile(boolean param_walkable, String imagePath)
  {
    walkable = param_walkable;
    myImage = loadImage(imagePath);
    myMask = loadImage("DecorMasque.jpg");
    myImage.mask(myMask);
  } 
  
  void display(int x, int y)
  {
    image(myImage, x, y);
  }
}

